package com.itheima.web.listener;

import com.itheima.autoconfig.huawei.HuaWeiUGCTemplate;
import com.itheima.domain.mongo.Movement;
import com.itheima.service.mongo.MovementService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(consumerGroup = "movement" , topic = "tanhua-movement-161")
public class MovementListener implements RocketMQListener<String> {

    @Reference
    private MovementService movementService;

    @Autowired
    private HuaWeiUGCTemplate huaWeiUGCTemplate;
    @Override
    public void onMessage(String movementId) {
        System.out.println("开始审核数据");
        //1.查询数据
        Movement movement = movementService.findMovement(movementId);
        //2.审核数据 要求图片和视频 必须有才能发布动态
        boolean flag1 = huaWeiUGCTemplate.textContentCheck(movement.getTextContent());
        boolean flag2 = huaWeiUGCTemplate.imageContentCheck(movement.getMedias().toArray(new String[]{}));
        if(flag1 && flag2){//审核通过
            movement.setState(1);//通过
        }else{
            movement.setState(2);//驳回
        }
        if (movement == null) {
            movementService.save(movement);//有就是修改 没有就是保存
        } else {
            movementService.update(movement);
        }

    }
}
